<?php
namespace yan\sign_google\factory;

class Oauth2 extends \yan\sign_google\AbstractFactory{
	public $environment;
	public $curl;
	private $token;
	function build($environment, $curl)
    {
        $this->environment = $environment;
        $this->curl = $curl;
        $this->init();
        return $this;
    }
    public function init(){

    }
	public function run($data=[]){

	}
	public function setAccessToken($token)
    {
        if (is_string($token)) {
            if ($json = json_decode($token, true)) {
                $token = $json;
            } else {
                // assume $token is just the token string
                $token = [
                    'access_token' => $token,
                ];
            }
        }
        if ($token == null) {
            throw new \InvalidArgumentException('invalid json token');
        }
        if (!isset($token['access_token'])) {
            throw new \InvalidArgumentException("Invalid token format");
        }
        $this->token = $token;
    }
}